Primer Exercises

Unidata Python Workshop


Exercises 1

Using the function pressure_to_height_std, can you calculate the height of the 700 millibar level assuming a standard atmosphere?


In [ ]:

What is the windchill when the temperature is 263K and the winds are blowing at 20 m/s? (Bonus points: find it in Fahrenheit)


In [ ]:

Using only values from metpy.constants, what is the dry adiabatic lapse rate? ($\Gamma_d = \frac{g}{C_{pd}}$)


In [ ]:


Exercises 2

Heat index is only defined for temperatures >= 80F and relative humidity values >= 40%. Using the data generated below, use boolean indexing to extract the data where heat index has a valid value.


In [ ]:
# Our import for numpy and metpy
import numpy as np
from metpy.units import units

# Here's the "data"
np.random.seed(19990503)  # Make sure we all have the same data
temp = (20 * np.cos(np.linspace(0, 2 * np.pi, 100)) +
        80 + 2 * np.random.randn(100)) * units.degF
rh = (np.abs(20 * np.cos(np.linspace(0, 4 * np.pi, 100)) +
              50 + 5 * np.random.randn(100))) * units('percent')


# Create a mask for the two conditions described above
# good_heat_index = 



# Use this mask to grab the temperature and relative humidity values that together
# will give good heat index values
# temp[] ?


# BONUS POINTS: Plot only the data where heat index is defined by
# inverting the mask (using `~mask`) and setting invalid values to np.nan